package cmd

import (
	"fmt"

	"github.com/spf13/cobra"

	"gitee.com/okatu-loli/oc_contributor_fanyuxiao/pkg/security"
)

var (
	imageName      string
	failOnCritical bool
)

// scanCmd represents the scan command
var scanCmd = &cobra.Command{
	Use:   "scan",
	Short: "scan container image for vulnerabilities",
	RunE: func(cmd *cobra.Command, args []string) error {
		if imageName == "" {
			return fmt.Errorf("image name is required")
		}
		return security.ScanImage(imageName, failOnCritical)
	},
}

func init() {
	rootCmd.AddCommand(scanCmd)

	scanCmd.Flags().StringVarP(&imageName, "image", "i", "", "container image to scan")
	scanCmd.Flags().BoolVar(&failOnCritical, "fail-on-critical", false, "fail if critical vulnerabilities are found")
}
